package com.hawthorn.admin.controller.syslog;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hawthorn.admin.service.syslog.SysLogService;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * <p>todo 日志管理</p>
 * @author: guohao | 2607728024@qq.com
–
 * @created: 2022/7/21 15:28
 * @version v1.0.1
 * @copyright: Copyright (c) 2022 guohao
 */
@Api(tags = {"admin-syslog"})
@RestController
@RequestMapping("/syslog/")
@Slf4j
public class SysLogController
{

  @Resource
  private SysLogService sysLogService;

  /**
   * <p>todo 获取用户登录日志</p>
   * @author: guohao 2607728024@qq.com
   * @date: 2022/7/4 15:23
   * @version: 1.0.1
   */
  @ApiOperation(value = "个人中心-> 获取用户登录日志", notes = "获取用户登录日志")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findLogInOperateLog")
  public IPage<Map<String, Object>> findLogInOperateLog(@RequestBody String params)
  {
    return sysLogService.findLogInOperateLog(params);
  }

  /**
   * <p>todo 获取用户操作日志</p>
   * @author: guohao 2607728024@qq.com
   * @date: 2022/7/7 16:06
   * @version: 1.0.1
   */
  @ApiOperation(value = "个人中心-> 获取用户操作日志", notes = "获取用户操作日志")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findOperationLog")
  public IPage<Map<String, Object>> findOperationLog(@RequestBody String params)
  {
    return sysLogService.findOperationLog(params);
  }

  /**
   * <p>todo 导出用户操作日志</p>
   * @author: guohao 2607728024@qq.com
   * @date: 2022/7/12 9:44
   * @version: 1.0.1
   */
  @ApiOperation(value = "导出->导出用户操作日志", notes = "导出用户操作日志")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = String.class),
      @ApiImplicitParam(name = "param", value = "param", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportOperationLog")
  public void exportOperationLog(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    sysLogService.exportOperationLog(response, "用户操作日志导出", param);
  }

  /**
   * <p>todo 导出用户登录日志</p>
   * @author: guohao 2607728024@qq.com
   * @date: 2022/7/12 9:48
   * @version: 1.0.1
   */
  @ApiOperation(value = "导出->导出用户登录日志", notes = "导出用户登录日志")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = String.class),
      @ApiImplicitParam(name = "param", value = "param", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportLogInOperateLog")
  public void exportLogInOperateLog(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    sysLogService.exportLogInOperateLog(response, "用户登录日志导出", param);
  }
}
